package com.akami.recipe;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



import xframe.ctl.XAction;
import xframe.util.db.Row;
import xframe.util.db.Transaction;

public class RecipeAction  extends XAction{
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			   HttpServletRequest request, HttpServletResponse response)
			   throws Exception {
				Row	req			=	getRequestInfo(request);
				IndexFm indexFm = new IndexFm();
				indexFm = (IndexFm)form;
					

				
				
				try{
					// 디비연결 시작
					Transaction.start(request);		
					System.out.println("==============================");
					System.out.println(" 디비연결 시작");
					System.out.println("==============================");
					HttpSession session = request.getSession();
					req.put("s_name", session.getAttribute("name"));
					req.put("s_email", session.getAttribute("email"));
					
	
					String 	listQueryName	=	"recipe.indexRecipe";
					String	listQuery 		=	mappingQuery(req, listQueryName);	
			
					simpleExecuteQuery(request, listQuery, listQueryName);
					ArrayList indexRecipeLIST = (ArrayList)request.getAttribute("recipe.indexRecipe");
					Row indexRecipeMap	=	(Row)indexRecipeLIST.get(0);
					req.put("recipe_pk", indexRecipeMap.get("recipe_pk"));
					
					 	listQueryName	=	"recipe.indexMaterial";
						listQuery 		=	mappingQuery(req, listQueryName);	
					
					simpleExecuteQuery(request, listQuery, listQueryName);
					
					listQueryName	=	"recipe.indexSourceMaterial";
					listQuery 		=	mappingQuery(req, listQueryName);	
					
					simpleExecuteQuery(request, listQuery, listQueryName);
					
					
					listQueryName	=	"recipe.attachementStepByStep";
					listQuery 		=	mappingQuery(req, listQueryName);	
					
					simpleExecuteQuery(request, listQuery, listQueryName);												
			
					//디비연결 종
			        Transaction.end(request);
		        
				}catch(Exception e){
					e.printStackTrace();
					Transaction.rollback(request, response);
					req.put("system_error", e.toString());
					return mapping.findForward( "system_error" );
				}        
			  return mapping.findForward("index");
			}

}
